package com.ruoyi.web.controller.cms;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.cms.domain.CmsPolicyType;
import com.ruoyi.cms.service.ICmsPolicyTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 政策栏目Controller
 * 
 * @author hct
 * @date 2022-01-22
 */
@RestController
@RequestMapping("/cms/policy/type")
public class CmsPolicyTypeController extends BaseController
{
    @Autowired
    private ICmsPolicyTypeService cmsPolicyTypeService;

    /**
     * 查询政策栏目列表
     */
    @PreAuthorize("@ss.hasPermi('cms:policytype:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsPolicyType cmsPolicyType)
    {
        startPage();
        List<CmsPolicyType> list = cmsPolicyTypeService.selectCmsPolicyTypeList(cmsPolicyType);
        return getDataTable(list);
    }

    /**
     * 导出政策栏目列表
     */
    @PreAuthorize("@ss.hasPermi('cms:policytype:export')")
    @Log(title = "政策栏目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsPolicyType cmsPolicyType)
    {
        List<CmsPolicyType> list = cmsPolicyTypeService.selectCmsPolicyTypeList(cmsPolicyType);
        ExcelUtil<CmsPolicyType> util = new ExcelUtil<CmsPolicyType>(CmsPolicyType.class);
        util.exportExcel(response, list, "政策栏目数据");
    }

    /**
     * 获取政策栏目详细信息
     */
    @PreAuthorize("@ss.hasPermi('cms:policytype:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(cmsPolicyTypeService.selectCmsPolicyTypeById(id));
    }

    /**
     * 新增政策栏目
     */
    @PreAuthorize("@ss.hasPermi('cms:policytype:add')")
    @Log(title = "政策栏目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsPolicyType cmsPolicyType)
    {
        return toAjax(cmsPolicyTypeService.insertCmsPolicyType(cmsPolicyType));
    }

    /**
     * 修改政策栏目
     */
    @PreAuthorize("@ss.hasPermi('cms:policytype:edit')")
    @Log(title = "政策栏目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsPolicyType cmsPolicyType)
    {
        return toAjax(cmsPolicyTypeService.updateCmsPolicyType(cmsPolicyType));
    }

    /**
     * 删除政策栏目
     */
    @PreAuthorize("@ss.hasPermi('cms:policytype:remove')")
    @Log(title = "政策栏目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsPolicyTypeService.deleteCmsPolicyTypeByIds(ids));
    }
}
